<?php
	/*
	**
	** @Class DB
	** @description Class to mada reference to the data base
	**
	*/
	class DB{
		var
			$db, 		//database connection
			$sql,		//execute statement  
			$numRows,	//number of records returned
			$resultado, //
			$row;		//record set
		
		/*
		**
		** @method() DB
		** @description constructor of the class, creates de data base connection
		**
		*/
		function DB(){
			if(!$this->db){
				include ('../lib/db.php');
				if($db=mysql_connect(_dataDB,_dataDBUser,_dataDBPwd)){
				 	if(mysql_select_db(_dataSource)){
						$this->db=$db;
					}else{
						echo '<h1>ERROR- Could not connect to the data base</h1>';
						exit();
					}
				}else{
					echo '<h1>ERROR- Could not connect to the server</h1>';
					exit();
				}
			}
		}
		
		/*
		**
		** @method() query
		** @description executes a query to the data base
		** @return resource
		**
		*/
		function query($stmt){
			$this->sql=mysql_query($stmt,$this->db);
			if(! mysql_error()){
				return $this->sql;
			}else{
				return $this->errorHandler();
			}
		}
		
		/*
		**
		** @method() idGenerated
		** @description function to return the last id inserted by an auto_increment
		**
		*/
		function idGenerated(){
			return mysql_insert_id();
		}
		
		/*
		**
		** @method() indeup
		** @description function to insert,delete or update the data base
		**
		*/
		function indeup($stmt){
			if(!mysql_query($stmt,$this->db))
				$this->errorHandler();
			else
				return true;				
		}
		
		/*
		**
		** @method() getRow
		** @description return data from a result
		** @return array of data
		**
		*/
		function getRow($tipo= MYSQL_ASSOC){
			$this->resultado = @mysql_fetch_array($this->sql);
			return $this->resultado;
		}
		
		/*
		**
		** @method() total
		** @description number of registers from a result
		** @return integer
		**
		*/
		function total($tipo= MYSQL_ASSOC){
			$this->numRows = @mysql_num_rows($this->sql);
			return $this->numRows;
		}
		
		/*
		**
		** @method() errorHandler
		** @description error handler
		**
		*/
		function errorHandler(){
			echo '<h1>ERROR- No '.mysql_errno().'
				  <br />Description'.mysql_error().'</h1>';
			exit();
		}
		
		/*
		**
		** @method() close
		** @description function to finalize the data base conection
		**
		*/
		function close(){
			if(isset($this->sql))
				@mysql_free_result($this->sql);
			mysql_close($this->db);
		}
	}
?>